function p = featureslong(zeta,T,losses)

%these times are _distance_ from first loss

%losses is a column vector with the losses
%we assume at least one loss, so it is distance from first loss



if losses(end)<T
    losses = [losses; T]; %this will make sure we go up to time T
end

%initializations
Nl = size(losses,1);
t1 = losses(1);
p = ones(T,1);
ctsum = 0;
t = t1-1;  



%loop over each loss
%should allow this to continue after a loss
for k = 1:Nl-1
    %time of the loss
    tl = losses(k);
    %time of next loss
    tlnext = losses(k+1);
    taumax = tlnext-tl;
    for tau = 1:taumax
        t = t+1; %calendar time
        ct = zeta*(1-zeta)^(tau-1); %decay of context away from tl
        p(t+1) = p(t)*(1- ct*(1-ct)/(1+ctsum));
        ctsum = ctsum +ct;
    end
 
end



%figure(1)
%plot([1:T],.5*p)



